package com.queclink.ycm.entity.data.useless;

import com.alibaba.fastjson.JSONObject;
import com.queclink.ycm.common.utils.HexUtils;
import com.queclink.ycm.entity.data.Data;
import com.queclink.ycm.entity.data.Data82;

/**
 * @author jim.li
 * @email jim.li@queclink.com
 * @date 2021-12-27 11:59:00
 */
public class Data260 extends Data {

    private String IgnitionOnTime;
    private String IgnitionOnLocation;
    private String IgnitionOffTime;
    private String IgnitionOffLocation;
    private String CurrentMileage;
    private String FuelConsumption;
    private String MaxSpeed;
    private String IdlingTime;
    private String IdlingFuelConsumption;
    private String HarshAccelerationCounts;
    private String HarshBrakeCounts;
    private String HarshTurnCounts;
    private String TripAMileage;
    private String TripBMileage;
    private String TotalMileage;
    private String TotalFuelConsumption;
    private String TotalDrivingTime;

    public String getIgnitionOnTime(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        String ignitionOnTime = jsonObject.getString("IgnitionOnTime");
        String s = HexUtils.LongStrToHex(ignitionOnTime, 8);
        sb.append(s);
        return sb.toString();
    }

    public String getIgnitionOnLocation(JSONObject jsonObject) {
        JSONObject ignitionOnLocation = jsonObject.getJSONObject("IgnitionOnLocation");
        Data82 data82 = new Data82();
        String s = data82.combine82(ignitionOnLocation);
        return s;
    }

    public String getIgnitionOffTime(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        String ignitionOffTime = jsonObject.getString("IgnitionOffTime");
        String s = HexUtils.LongStrToHex(ignitionOffTime, 8);
        sb.append(s);
        return sb.toString();
    }

    public String getIgnitionOffLocation(JSONObject jsonObject) {
        JSONObject ignitionOffLocation = jsonObject.getJSONObject("IgnitionOffLocation");
        Data82 data82 = new Data82();
        String s = data82.combine82(ignitionOffLocation);
        return s;
    }

    public String getCurrentMileage(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer currentMileage = jsonObject.getInteger("CurrentMileage");
        String s = HexUtils.intToHex(currentMileage, 8);
        sb.append(s);
        return sb.toString();
    }

    public String getFuelConsumption(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer fuelConsumption = jsonObject.getInteger("FuelConsumption");
        String s = HexUtils.intToHex(fuelConsumption, 8);
        sb.append(s);
        return sb.toString();
    }

    public String getMaxSpeed(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer maxSpeed = jsonObject.getInteger("MaxSpeed");
        String s = HexUtils.intToHex(maxSpeed, 4);
        sb.append(s);
        return sb.toString();
    }

    public String getIdlingTime(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer idlingTime = jsonObject.getInteger("IdlingTime");
        String s = HexUtils.intToHex(idlingTime, 8);
        sb.append(s);
        return sb.toString();
    }

    public String getIdlingFuelConsumption(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer idlingFuelConsumption = jsonObject.getInteger("IdlingFuelConsumption");
        String s = HexUtils.intToHex(idlingFuelConsumption, 4);
        sb.append(s);
        return sb.toString();
    }

    public String getHarshAccelerationCounts(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer harshAccelerationCounts = jsonObject.getInteger("HarshAccelerationCounts");
        String s = HexUtils.intToHex(harshAccelerationCounts, 2);
        sb.append(s);
        return sb.toString();
    }

    public String getHarshBrakeCounts(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer harshBrakeCounts = jsonObject.getInteger("HarshBrakeCounts");
        String s = HexUtils.intToHex(harshBrakeCounts, 2);
        sb.append(s);
        return sb.toString();
    }

    public String getHarshTurnCounts(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer harshTurnCounts = jsonObject.getInteger("HarshTurnCounts");
        String s = HexUtils.intToHex(harshTurnCounts, 2);
        sb.append(s);
        return sb.toString();
    }

    public String getTripAMileage(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer tripAMileage = jsonObject.getInteger("TripAMileage");
        String s = HexUtils.intToHex(tripAMileage, 8);
        sb.append(s);
        return sb.toString();
    }

    public String getTripBMileage(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer tripBMileage = jsonObject.getInteger("TripBMileage");
        String s = HexUtils.intToHex(tripBMileage, 8);
        sb.append(s);
        return sb.toString();
    }

    public String getTotalMileage(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer totalMileage = jsonObject.getInteger("TotalMileage");
        String s = HexUtils.intToHex(totalMileage, 8);
        sb.append(s);
        return sb.toString();
    }

    public String getTotalFuelConsumption(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer totalFuelConsumption = jsonObject.getInteger("TotalFuelConsumption");
        String s = HexUtils.intToHex(totalFuelConsumption, 8);
        sb.append(s);
        return sb.toString();
    }

    public String getTotalDrivingTime(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer totalDrivingTime = jsonObject.getInteger("TotalDrivingTime");
        String s = HexUtils.intToHex(totalDrivingTime, 8);
        sb.append(s);
        return sb.toString();
    }

    public String getDataID() {
        // data260
        return "8104";
    }

    public String getLength() {
        return "5B";
    }

    @Override
    public String combine(JSONObject jsonObject) throws Exception {
        StringBuffer sb = new StringBuffer();
        sb.append(this.getDataID());
        sb.append(this.getLength());
        sb.append(this.getIgnitionOnTime(jsonObject));
        sb.append(this.getIgnitionOnLocation(jsonObject));
        sb.append(this.getIgnitionOffTime(jsonObject));
        sb.append(this.getIgnitionOffLocation(jsonObject));
        sb.append(this.getCurrentMileage(jsonObject));
        sb.append(this.getFuelConsumption(jsonObject));
        sb.append(this.getMaxSpeed(jsonObject));
        sb.append(this.getIdlingTime(jsonObject));
        sb.append(this.getIdlingFuelConsumption(jsonObject));
        sb.append(this.getHarshAccelerationCounts(jsonObject));
        sb.append(this.getHarshBrakeCounts(jsonObject));
        sb.append(this.getHarshTurnCounts(jsonObject));
        sb.append(this.getTripAMileage(jsonObject));
        sb.append(this.getTripBMileage(jsonObject));
        sb.append(this.getTotalMileage(jsonObject));
        sb.append(this.getTotalFuelConsumption(jsonObject));
        sb.append(this.getTotalDrivingTime(jsonObject));

        return sb.toString();
    }
}
